This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (April 2010) |
`
|
|||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Grave accent | |||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||
The grave accent ( ` ) ( /ˈɡreɪv/ or UK /ˈɡrɑːv/)[1] is a diacritical mark used in written Breton, Catalan, Corsican, Dutch, French, Greek (until 1982; see polytonic orthography), Italian, Macedonian, Mohawk, Norwegian, Occitan, Portuguese, Ligurian, Scottish Gaelic, Vietnamese, Welsh, Romansh, and other languages.
Contents |
The grave accent was first used in the polytonic orthography of Ancient Greek to mark a lower pitch than the high pitch of the acute accent. In modern practice, it is used to replace an acute accent in the last syllable of a word when the word is followed immediately by another word in the sentence.
Originally, however, the grave marked any syllable that was not marked with an acute or circumflex.[2] This practice was soon given up for the less laborious one of marking only the last syllable.
Since Modern Greek has a stress accent instead of a pitch accent, both the grave and circumflex have been replaced with an acute accent in the modern monotonic orthography.
The grave accent marks the stressed vowel of a word in Catalan and Italian.
General rule is that in Italian words ending with stressed -a, -i, -o, -u must be marked with a grave accent. So only words ending with stressed -e may bear both an acute accent or a grave accent (closed 'e' sound vs. open 'e' sound). Some examples are: città "city", morì "[he/she] died", virtù "virtue", Mosè "Moses", portò "[he/she/it] brought, carried". Especially with capital letters, or when using a keyboard without accented letters, an apostrophe is sometimes used instead of the proper accent, thus E’ instead of È "[he/she/it] is", though it is technically an error. Other mistakes arise from the misunderstanding of truncated and elided words: for example the phrase un po’, meaning "a little", which is the truncated version of un poco, is infrequently spelt as un pò. In Italian there are many pairs of words, one with an accent marked and the other not, with different pronunciation and meaning, such as pero "pear tree" and però "but", and Papa "Pope" and papà "dad" (the last example is also valid for Catalan).
In Bulgarian and Macedonian, the grave is used on the vowels а, о, у, е, и, ъ (Bulgarian only), to mark stress. It is particularly used in books for children or foreigners, or to distinguish between near-homophones: па̀ра steam, vapour and пара̀ cent/penny, money, въ̀лна wool and вълна̀ wave. In a few cases (mostly on the vowels е and и) the stress mark is orthographically required to distinguish words which are homonyms. For example, the Macedonian negation particle не is a homonym with the short-form of the direct object personal pronoun нe – thus нѐ. The grave in these cases forces the stress on the graved word-syllable, instead of having a different syllable in the stress group get accented. In turn, this changes the pronunciation and the whole meaning of the group.
In Ukrainian, Rusyn, Belarusian and Russian, the similar system was in use until the first half of the 20th century. Now the main stress is preferably being marked with an acute, and the role of grave is limited to mark secondary stress in compound words (in dictionaries and in linguistic literature).
In the descendants of Serbo-Croatian and in Slovene, the stressed syllabe can be short or long, as well as having rising or falling tone. To show this, these languages use (in dictionaries, orthography and grammar books etc.) four different stress marks (grave, acute, double grave and circumflex). The system is identical both in Latin and Cyrillic scripts.
In modern Church Slavonic, there are three stress marks (acute, grave and circumflex). There is no phonetical distinction between them, only the orthographical one. Grave is typically used when the stressed vowel is the last letter of a multi-letter word.
In Ligurian, the grave accent marks the accented short vowel of a word in à (sound [a]), è (sound [ɛ]), ì (sound [i]) and ù (sound [y]). In the case of ò, it is used for the short sound of [O], but it may not be the stressed vowel of the word.
The grave accent marks the height or openness of the vowels e and o, indicating that they are pronounced open: è [ɛ] (as opposed to é [e]); ò [ɔ] (as opposed to ó [o]), in several Roman languages:
The grave accent is used to distinguish homophones in several languages:
In Welsh, the accent is used to denote a short vowel sound in a word which would otherwise be pronounced with a long vowel sound, for example mẁg [mʊɡ] "mug" versus mwg [muːɡ] "smoke".
In Scottish Gaelic, it denotes a long vowel – the use of acute accents is seen in older texts, but is no longer allowed according to the new orthographical conventions.
In some tonal languages such as Vietnamese and Mandarin Chinese (when written in Hanyu Pinyin or Zhuyin Fuhao), the grave accent is used to indicate a falling tone. The alternative to the grave accent in Mandarin is the numeral 4 after the syllable: pà = pa4.
In African languages, the grave accent is often used to indicate a low tone, e.g. Nobiin jàkkàr "fish-hook", Yoruba àgbọ̀n "chin", Hausa màcè "woman".
The grave accent is used to represent the low tone in Kanien'kéha or Mohawk.
In Portuguese, the grave accent indicates the contraction of two consecutive vowels in adjacent words (crasis). For example, instead of a aquela hora ("at that hour"), one says and writes àquela hora.
In Hawaiian, the grave accent (alone, not placed over another character) is sometimes encountered as a typographically easier substitute for the ʻokina, e.g. Hawai`i instead of Hawaiʻi.
The grave accent, although not standardly applied to any English words, is sometimes used in poetry and song lyrics to indicate that a vowel usually silent is to be pronounced, in order to fit the rhythm or meter. Most often, it is applied to a word ending with -ed. For instance, the word looked is usually pronounced /ˈlʊkt/ as a single syllable, with the e silent; when written as lookèd, the e is pronounced: /ˈlʊk.ɨd/ look-ed). It can also be used in this capacity to distinguish certain pairs of identically spelled words like the past tense of learn, learned /ˈlɜrnd/, from the adjective learnèd /ˈlɜrn.ɨd/ (for example, "a very learnèd man").
Italics, with appropriate accents, are generally applied to foreign terms that are uncommonly used in or have not been assimilated into English: for example, vis-à-vis, pièce de résistance and crème brûlée.
additional diacritic |
character | Unicode | HTML |
---|---|---|---|
Latin | |||
— | À à |
U+00C0 U+00E0 |
À à |
È è |
U+00C8 U+00E8 |
È è |
|
Ì ì |
U+00CC U+00EC |
Ì ì |
|
Ò ò |
U+00D2 U+00F2 |
Ò ò |
|
Ù ù |
U+00D9 U+00F9 |
Ù ù |
|
Ǹ ǹ |
U+01F8 U+01F9 |
Ǹ ǹ |
|
Ẁ ẁ |
U+1E80 U+1E81 |
Ẁ ẁ |
|
Ỳ ỳ |
U+1EF2 U+1EF3 |
Ỳ ỳ |
|
diaeresis | Ǜ ǜ |
U+01DB U+01DC |
Ǜ ǜ |
double grave |
Ȁ ȁ |
U+0200 U+0201 |
Ȁ ȁ |
Ȅ ȅ |
U+0204 U+0205 |
Ȅ ȅ |
|
Ȉ ȉ |
U+0208 U+0209 |
Ȉ ȉ |
|
Ȍ ȍ |
U+020C U+020D |
Ȍ ȍ |
|
Ȑ ȑ |
U+0210 U+0211 |
Ȑ ȑ |
|
Ȕ ȕ |
U+0214 U+0215 |
Ȕ ȕ |
|
macron | Ḕ ḕ |
U+1E14 U+1E15 |
Ḕ ḕ |
Ṑ ṑ |
U+1E50 U+1E51 |
Ṑ ṑ |
|
circumflex | Ầ ầ |
U+1EA6 U+1EA7 |
Ầ ầ |
Ề ề |
U+1EC0 U+1EC1 |
Ề ề |
|
Ồ ồ |
U+1ED2 U+1ED3 |
Ồ ồ |
|
breve | Ằ ằ |
U+1EB0 U+1EB1 |
Ằ ằ |
horn | Ờ ờ |
U+1EDC U+1EDD |
Ờ ờ |
Ừ ừ |
U+1EEA U+1EEB |
Ừ ừ |
|
Cyrillic | |||
— | Ѐ ѐ |
U+0400 U+0450 |
Ѐ ѐ |
Ѝ ѝ |
U+040D U+045D |
Ѝ ѝ |
|
Ѷ ѷ |
U+0476 U+0477 |
Ѷ ѷ |
|
Greek (varia) | |||
— | ` | U+1FEF | ` |
Ὰ ὰ |
U+1FBA U+1F70 |
Ὰ ὰ |
|
Ὲ ὲ |
U+1FC8 U+1F72 |
Ὲ ὲ |
|
Ὴ ὴ |
U+1FCA U+1F74 |
Ὴ ὴ |
|
Ὶ ὶ |
U+1FDA U+1F76 |
Ὶ ὶ |
|
Ὸ ὸ |
U+1FF8 U+1F78 |
Ὸ ὸ |
|
Ὺ ὺ |
U+1FEA U+1F7A |
Ὺ ὺ |
|
Ὼ ὼ |
U+1FFA U+1F7C |
Ὼ ὼ |
|
smooth breathing |
῍ | U+1FCD | ῍ |
Ἂ ἂ |
U+1F0A U+1F02 |
Ἂ ἂ |
|
Ἒ ἒ |
U+1F1A U+1F12 |
Ἒ ἒ |
|
Ἢ ἢ |
U+1F2A U+1F22 |
Ἢ ἢ |
|
Ἲ ἲ |
U+1F3A U+1F32 |
Ἲ ἲ |
|
Ὂ ὂ |
U+1F4A U+1F42 |
Ὂ ὂ |
|
— ὒ |
— U+1F52 |
— ὒ |
|
Ὢ ὢ |
U+1F6A U+1F62 |
Ὢ ὢ |
|
rough breathing |
῝ | U+1FDD | ῝ |
Ἃ ἃ |
U+1F0B U+1F03 |
Ἃ ἃ |
|
Ἓ ἓ |
U+1F1B U+1F13 |
Ἓ ἓ |
|
Ἣ ἣ |
U+1F2B U+1F23 |
Ἣ ἣ |
|
Ἳ ἳ |
U+1F3B U+1F33 |
Ἳ ἳ |
|
Ὃ ὃ |
U+1F4B U+1F43 |
Ὃ ὃ |
|
Ὓ ὓ |
U+1F5B U+1F53 |
Ὓ ὓ |
|
Ὣ ὣ |
U+1F6B U+1F63 |
Ὣ ὣ |
|
iota subscript |
— ᾲ |
— U+1FB2 |
— ᾲ |
— ῂ |
— U+1FC2 |
— ῂ |
|
— ῲ |
— U+1FF2 |
— ῲ |
|
smooth breathing, iota subscript |
ᾊ ᾂ |
U+1F8A U+1F82 |
ᾊ ᾂ |
ᾚ ᾒ |
U+1F9A U+1F92 |
ᾚ ᾒ |
|
ᾪ ᾢ |
U+1FAA U+1FA2 |
ᾪ ᾢ |
|
rough breathing, iota subscript |
ᾋ ᾃ |
U+1F8B U+1F83 |
ᾋ ᾃ |
ᾛ ᾓ |
U+1F9B U+1F93 |
ᾛ ᾓ |
|
ᾫ ᾣ |
U+1FAB U+1FA3 |
ᾫ ᾣ |
|
diaeresis | ῭ | U+1FED | ῭ |
— ῒ |
— U+1FD2 |
— ῒ |
|
— ῢ |
— U+1FE2 |
— ῢ |
The ISO-8859-1 character encoding includes the letters à, è, ì, ò, ù, and their respective capital forms. Dozens more letters with the grave accent are available in Unicode.
In the ASCII character set the grave accent is encoded as character 96, hex 60. Unicode also provides the grave accent as a combining character, encoded as 768, hex 300. Outside the US, character 96 is often replaced by accented letters. In the French ISO 646 standard, the character at this position is µ. Many older UK computers, such as the ZX Spectrum and BBC Micro, have the £ symbol as character 96, though the British ISO 646 variant ultimately placed this symbol at position 35 instead.
On many computer keyboards, the grave accent occupies a key by itself, and is meant to be combined with vowels as a multi-key combination or as a dead key to modify the following letter.
On a Mac, to get a character such as à, the user must type Option-` and then the vowel. For example, to make à, the user must type Option-` and then 'a', and to make À, the user must type Option-` and then Shift-a.
On a system running the X Window System, to get a character such as à, the user should press compose and ` together, then the vowel. The compose key on modern keyboards is usually mapped to a Windows key or shift+AltGR.[3]
On a US and UK QWERTY keyboard, the grave accent key is placed in the top left corner. In many PC based computer games, the key is used to open the console window, allowing the user to execute commands via a CLI.
Programmers have used the grave accent symbol by itself (i.e. not combined with some letter) for a number of tasks. In this role, it is known as a backquote or backtick.
When using TeX to typeset text, the backtick character is used as a syntax to represent curly opening quotes. For example, `
is rendered as single opening curly quote (‘) and ``
is a double curly opening quote (“). It is also used for using the numeric ASCII value of an ASCII character wherever a number is expected.
Many of the Unix shells and the programming languages Perl, PHP, and Ruby use pairs of this character to indicate command substitution, that is, substitution of the standard output from one command into a line of text defining another command. For example, the code line:
echo It is now `date`
might result, after command substitution, in the command:
echo It is now Tue Jun 26 16:38:04 GMT 2012
which then on execution produces the output:
It is now Tue Jun 26 16:38:04 GMT 2012
In the Bash shell, the `...` is deprecated in favour of $(...).[4] The same is true of Z shell.[5]
In Lisp macro systems, the backquote character (called quasiquote in Scheme) introduces a quoted expression in which comma-substitution may occur. It is identical to the plain quote, except that symbols prefixed with a comma will be replaced with those symbols' values as variables. This is roughly analogous to the Unix shell's variable interpolation with $
inside double quotes.
In m4, it is used together with an apostrophe to quote strings (to suppress or defer macro expansion).
In MySQL, it is used in queries as a table and database classifier.
In Pico, the backquote is used to indicate comments in the programming language.
In Haskell, a function name surrounded by backquote allows you to use it as an infix operator.
In OCaml, the backquote is used to indicate polymorphic variants.
In Tom_(pattern_matching_language)Tom, the backquote is used to create a new term or to call an existing term.
In Go, the backquote is used to surround a raw string literal.
Windows PowerShell uses the backquote as the escape character. For example, a newline character is denoted `n
. Most commonly used programming languages use a backslash as the escape character (e.g. \n
) but because Windows allows the backslash as a path separator, it would have been impractical for PowerShell to use backslash for a different purpose. To get the `
character itself, use two backticks. For example the nullable boolean of .NET is specified in PowerShell as [Nullable``1[System.Boolean]]
.
Prior to Python 3.0, backticks were used as a synonym for the repr()
function, which converts its argument to a string suitable for a programmer to view. However, this feature was removed in Python 3.0. Backticks are also used extensively in the reStructuredText plain text markup language (implemented in the Python docutils package).
In Verilog, the grave accent is used to define constants (e.g. after the line `define NUM 100
, `NUM
can be used as a synonym for 100
) whereas the apostrophe is used in specifying sized constants (for example, 5'd10
is a 5-bit constant with the value 10). Accidental use of an apostrophe instead of a grave accent and vice versa is a source of frequent beginner mistakes in the language.
In Unlambda, the backquote character denotes function application.
In BBC BASIC, the backquote character is valid within (and at the beginning of) a variable, structure, procedure or function name.
Aa | Bb | Cc | Dd | Ee | Ff | Gg | Hh | Ii | Jj | Kk | Ll | Mm | Nn | Oo | Pp | Rr | Ss | Tt | Uu | Vv | Ww | Xx | Yy | Zz | ||
Letters using grave accent ( ◌̀ )
|
||||||||||||||||||||||||||
Àà | Èè | Ì ì | Ǹǹ | Òò | Ùù | Ẁẁ | Ỳỳ | |||||||||||||||||||
Related
|
||||||||||||||||||||||||||
Look up à or è in Wiktionary, the free dictionary. |
This article contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. (July 2011) |
In computing, a newline,[1] also known as a line break or end-of-line (EOL) marker, is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line—that is, on the next line below the text immediately preceding the newline. The actual codes representing a newline vary across operating systems, which can be a problem when exchanging text files between systems with different newline representations.
There is also some confusion whether newlines terminate or separate lines. If a newline is considered a separator, there will be no newline after the last line of a file. The general convention on most systems is to add a newline even after the last line, i.e. to treat newline as a line terminator. Some programs have problems processing the last line of a file if it is not newline terminated. Conversely, programs that expect newline to be used as a separator will interpret a final newline as starting a new (empty) line.
In text intended primarily to be read by humans using software which implements the word wrap feature, a newline character typically only needs to be stored if a line break is required independent of whether the next word would fit on the same line, such as between paragraphs and in vertical lists. See hard return and soft return.
Contents |
Software applications and operating systems usually represent a newline with one or two control characters:
Most textual Internet protocols (including HTTP, SMTP, FTP, IRC and many others) mandate the use of ASCII CR+LF (0x0D 0x0A) on the protocol level, but recommend that tolerant applications recognize lone LF as well. In practice, there are many applications that erroneously use the C newline character '\n' instead (see section Newline in programming languages below). This leads to problems when trying to communicate with systems adhering to a stricter interpretation of the standards; one such system is the qmail MTA that actively refuses to accept messages from systems that send bare LF instead of the required CR+LF.[2]
FTP has a feature to transform newlines between CR+LF and LF only when transferring text files. This must not be used on binary files. Usually binary files and text files are recognised by checking their filename extension.
The Unicode standard defines a large number of characters that conforming applications should recognize as line terminators:[3]
LF: Line Feed, U+000A
VT: Vertical Tab, U+000B
FF: Form Feed, U+000C
CR: Carriage Return, U+000D
CR+LF: CR (U+000D) followed by LF (U+000A)
NEL: Next Line, U+0085
LS: Line Separator, U+2028
PS: Paragraph Separator, U+2029
This may seem overly complicated compared to an approach such as converting all line terminators to a single character, for example LF. However, Unicode was designed to preserve all information when converting a text file from any existing encoding to Unicode and back. Therefore, Unicode should contain characters included in existing encodings. NEL is included in ISO-8859-1[citation needed] and EBCDIC (0x15). The approach taken in the Unicode standard allows round-trip transformation to be information-preserving while still enabling applications to recognize all possible types of line terminators.
Recognizing and using the newline codes greater than 0x7F is not often done. They are multiple bytes in UTF-8 and the code for NEL has been used as the ellipsis ('…') character in Windows-1252. For instance:
ASCII was developed simultaneously by the ISO and the ASA, the predecessor organization to ANSI. During the period of 1963–1968, the ISO draft standards supported the use of either CR+LF or LF alone as a newline, while the ASA drafts supported only CR+LF.
The sequence CR+LF was in common use on many early computer systems that had adopted Teletype machines, typically a Teletype Model 33 ASR, as a console device, because this sequence was required to position those printers at the start of a new line. On these systems, text was often routinely composed to be compatible with these printers, since the concept of device drivers hiding such hardware details from the application was not yet well developed; applications had to talk directly to the Teletype machine and follow its conventions.
Most minicomputer systems from DEC used this convention. CP/M used it as well, to print on the same terminals that minicomputers used. From there MS-DOS (1981) adopted CP/M's CR+LF in order to be compatible, and this convention was inherited by Microsoft's later Windows operating system.
The separation of the two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in one-character time. That is why the sequence was always sent with the CR first. In fact, it was often necessary to send extra characters (extraneous CRs or NULs, which are ignored) to give the print head time to move to the left margin. Even many early video displays required multiple character times to scroll the display.
The Multics operating system began development in 1964 and used LF alone as its newline. Multics used a device driver to translate this character to whatever sequence a printer needed (including extra padding characters), and the single byte was much more convenient for programming. The seemingly more obvious choice of CR was not used, as a plain CR provided the useful function of overprinting one line with another, and thus it was useful to not translate it. Unix followed the Multics practice, and later systems followed Unix.
To facilitate the creation of portable programs, programming languages provide some abstractions to deal with the different types of newline sequences used in different environments.
The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, these are not required to be equivalent to the ASCII LF and CR control characters. The C standard only guarantees two things:
On Unix platforms, where C originated, the native newline sequence is ASCII LF (0x0A), so '\n' was simply defined to be that value. With the internal and external representation being identical, the translation performed in text mode is a no-op, and text mode and binary mode behave the same. This has caused many programmers who developed their software on Unix systems simply to ignore the distinction completely, resulting in code that is not portable to different platforms.
The C library function fgets() is best avoided in binary mode because any file not written with the UNIX newline convention will be misread. Also, in text mode, any file not written with the system's native newline sequence (such as a file created on a UNIX system, then copied to a Windows system) will be misread as well.
Another common problem is the use of '\n' when communicating using an Internet protocol that mandates the use of ASCII CR+LF for ending lines. Writing '\n' to a text mode stream works correctly on Windows systems, but produces only LF on Unix, and something completely different on more exotic systems. Using "\r\n" in binary mode is slightly better.
Many languages, such as C++, Perl,[6] and Haskell provide the same interpretation of '\n' as C.
Java, PHP,[7] and Python[8] provide the '\r\n' sequence (for ASCII CR+LF). In contrast to C, these are guaranteed to represent the values U+000A and U+000D, respectively.
The Java I/O libraries do not transparently translate these into platform-dependent newline sequences on input or output. Instead, they provide functions for writing a full line that automatically add the native newline sequence, and functions for reading lines that accept any of CR, LF, or CR+LF as a line terminator (see BufferedReader.readLine()). The System.getProperty() method can be used to retrieve the underlying line separator.
Example:
String eol = System.getProperty( "line.separator" ); String lineColor = "Color: Red" + eol;
Python permits "Universal Newline Support" when opening a file for reading, when importing modules, and when executing a file.[9]
Some languages have created special variables, constants, and subroutines to facilitate newlines during program execution.
The different newline conventions often cause text files that have been transferred between systems of different types to be displayed incorrectly. For example, files originating on Unix or Apple Macintosh systems may appear as a single long line on some Windows programs. Conversely, when viewing a file originating from a Windows computer on a Unix system, the extra CR may be displayed as ^M at the end of each line or as a second line break.
The problem can be hard to spot if some programs handle the foreign newlines properly while others do not. For example, a compiler may fail with obscure syntax errors even though the source file looks correct when displayed on the console or in an editor. On a Unix system, the command cat -v myfile.txt will send the file to stdout (normally the terminal) and make the ^M visible, which can be useful for debugging. Modern text editors generally recognize all flavours of CR / LF newlines and allow the user to convert between the different standards. Web browsers are usually also capable of displaying text files and websites which use different types of newlines.
The File Transfer Protocol can automatically convert newlines in files being transferred between systems with different newline representations when the transfer is done in "ASCII mode". However, transferring binary files in this mode usually has disastrous results: Any occurrence of the newline byte sequence—which does not have line terminator semantics in this context, but is just part of a normal sequence of bytes—will be translated to whatever newline representation the other system uses, effectively corrupting the file. FTP clients often employ some heuristics (for example, inspection of filename extensions) to automatically select either binary or ASCII mode, but in the end it is up to the user to make sure his or her files are transferred in the correct mode. If there is any doubt as to the correct mode, binary mode should be used, as then no files will be altered by FTP, though they may display incorrectly.
This article contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. (June 2010) |
Text editors are often used for converting a text file between different newline formats; most modern editors can read and write files using at least the different ASCII CR/LF conventions. The standard Windows editor Notepad is not one of them (although Wordpad and the MS-DOS Editor are).
Editors are often unsuitable for converting larger files. For larger files (on Windows NT/2000/XP) the following command is often used:
TYPE unix_file | FIND "" /V > dos_file
On many Unix systems, the dos2unix (sometimes named fromdos or d2u) and unix2dos (sometimes named todos or u2d) utilities are used to translate between ASCII CR+LF (DOS/Windows) and LF (Unix) newlines. Different versions of these commands vary slightly in their syntax. However, the tr command is available on virtually every Unix-like system and is used to perform arbitrary replacement operations on single characters. A DOS/Windows text file can be converted to Unix format by simply removing all ASCII CR characters with
tr -d '\r' < inputfile > outputfile
or, if the text has only CR newlines, by converting all CR newlines to LF with
tr '\r' '\n' < inputfile > outputfile
The same tasks are sometimes performed with awk, sed, Tr_(Unix) or in Perl if the platform has a Perl interpreter:
awk '{sub("$","\r\n"); printf("%s",$0);}' inputfile > outputfile # UNIX to DOS (adding CRs on Linux and BSD based OS that haven't GNU extensions) awk '{gsub("\r",""); print;}' inputfile > outputfile # DOS to UNIX (removing CRs on Linux and BSD based OS that haven't GNU extensions) sed -e 's/$/\r/' inputfile > outputfile # UNIX to DOS (adding CRs on Linux based OS that use GNU extensions) sed -e 's/\r$//' inputfile > outputfile # DOS to UNIX (removing CRs on Linux based OS that use GNU extensions) cat inputfile | tr -d "\r" > outputfile # DOS to UNIX (removing CRs using tr(1). Not Unicode compliant.) perl -pe 's/\r?\n|\r/\r\n/g' inputfile > outputfile # Convert to DOS perl -pe 's/\r?\n|\r/\n/g' inputfile > outputfile # Convert to UNIX perl -pe 's/\r?\n|\r/\r/g' inputfile > outputfile # Convert to old Mac
To identify what type of line breaks a text file contains, the file command can be used. Moreover, the editor Vim can be convenient to make a file compatible with the Windows notepad text editor. For example:
[prompt] > file myfile.txt myfile.txt: ASCII English text [prompt] > vim myfile.txt within vim :set fileformat=dos :wq [prompt] > file myfile.txt myfile.txt: ASCII English text, with CRLF line terminators
The following grep commands echo the filename (in this case myfile.txt) to the command line if the file is of the specified style:
grep -PL $'\r\n' myfile.txt # show UNIX style file (LF terminated) grep -Pl $'\r\n' myfile.txt # show DOS style file (CRLF terminated)
For Debian-based systems, these commands are used:
egrep -L $'\r\n' myfile.txt # show UNIX style file (LF terminated) egrep -l $'\r\n' myfile.txt # show DOS style file (CRLF terminated)
The above grep commands work under Unix systems or in Cygwin under Windows. Note that these commands make some assumptions about the kinds of files that exist on the system (specifically it's assuming only UNIX and DOS-style files—no Mac OS 9-style files).
This technique is often combined with find to list files recursively. For instance, the following command checks all "regular files" (e.g. it will exclude directories, symbolic links, etc.) to find all UNIX-style files in a directory tree, starting from the current directory (.), and saves the results in file unix_files.txt, overwriting it if the file already exists:
find . -type f -exec grep -PL '\r\n' {} \; > unix_files.txt
This example will find C files and convert them to LF style line endings:
find -name '*.[ch]' -exec fromdos {} \;
The file command also detects the type of EOL used:
file myfile.txt > myfile.txt: ASCII text, with CRLF line terminators
Other tools permit the user to visualise the EOL characters:
od -a myfile.txt cat -e myfile.txt hexdump -c myfile.txt
dos2unix, unix2dos, mac2unix, unix2mac, mac2dos, dos2mac can perform conversions. The flip[10] command is often used.